/**
 * 商品基础信息查询
 */
var oTable;
var isInit = true;
var page = $("#page").val();
$(function(){
	//初始化
	initDataTable();
	
	$('#search').click(function(){
		oTable.ajax.reload();
	});
});

function showBaseInfo(relateid){
	var info = oTable.page.info();
	var page =info.page; 
	var fromdate = $('#fromdate').val();
	var retdate = $('#retdate').val();
	var fromairport = $('#fromairport').val();
	var toairport = $('#toairport').val();
	var url = "editBaseInfo?relateid="+relateid+"&page="+page;
	if(fromdate!=''){
		url +="&fromdate="+fromdate;
	}
	if(retdate!=''){
		url +="&retdate="+retdate;
	}
	if(fromairport!=''){
		url +="&fromairport="+fromairport;
	}
	if(toairport!=''){
		url +="&toairport="+toairport;
	}
	window.location.href=url;
}
function initDataTable() {
	
	oTable = $('.examples').DataTable({
		"dom": '<"top">rt<"bottom"ip><"clear">',
		"ajax": {
			"type": "POST",
			"url": "query.ajax",
			"data": function(d) {
				if(isInit&& parseInt(page)!=0){
					d.start = parseInt(page)*10;
		    	}
				d.fromdate = $('#fromdate').val(),
				d.retdate = $('#retdate').val(),
				d.fromairport = $('#fromairport').val(),
				d.toairport = $('#toairport').val();
			}
		},
		//"processing": true,
        "serverSide": true,
		"ordering": false,
		"aLengthMenu": [5, 10, 20, 40 ],
		"iDisplayLength" : 10,
		"oLanguage": {
			"sUrl": "../static/js/datatable.cn.txt"
		},
		"aoColumns": [
		    {"mDataProp":"id"},
			{"mDataProp":"relateid"},
			{"mDataProp":"importdate"},
			{"mDataProp":"fromairport"},
			{"mDataProp":"toairport"},
			{"mDataProp":"transferairport"},
			{"mDataProp":"fromdate"},
			{"mDataProp":"todate"},
			{"mDataProp":"price"},
			{"mDataProp":"tax"},
			{"mDataProp":"total"},
			{"mDataProp":"stocks"},
			{"mDataProp":"changedstocks"},
			{"mDataProp":"takebackstocks"},
			{"mDataProp":"status"}
		],
		"columnDefs": [
		    {
		    	"targets": 0,
		    	"visible": false
		    },
   			
			{
				"targets": 5,
				"render":function(data,type,row){
					if(data==''|data==null|data=='null'){
						return "无";
					}
					return data;
				}
			
			}, 
			{
				"targets": 10,
				"render":function(data,type,row){
					return row.price+row.tax;
				}
			
			},
			{
				"targets": 14,
				"render":function(data,type,row){
					if(data==0){
						return "已导入";
					}else if(data==1){
						return "校验成功";
					}else if(data==2){
						return "校验失败";
					}else if(data==3){
						return "已投放";
					}else if(data==4){
						return "已调价投放";
					}else if(data==5){
						return "已回收";
					}
				}
			},
            {
                "render": function ( data, type, row ) {
             	   return '<a class="btn btn-info btn-xs" href="javascript:void(0);" onclick="javascript:showBaseInfo(' + row.relateid + ')" title="查看"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span>查看</a>&nbsp;&nbsp;' ;
                },
                "targets": 15
            }
       ],
      
       "initComplete": function(settings, json) {
    	   if(isInit&& parseInt(page)!=0){
    		   isInit = false;
    		   oTable.page(parseInt(page)).draw(false);
    	   }
       }
	});
	
}